<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"   
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content"> 
            <div class="Post">
                <h:form id="createTaskForm">
                    <h:panelGrid columns="2">
                        <h:outputText value="Task name"/>
                        <p:inputText id="taskName" required="true" style="width: 350px" value="#{taskBean.newTemplate.name}" />
                        <h:outputText value="Task description"/>
                        <p:inputTextarea id="taskDescr" style="width: 350px" required="true"  value="#{taskBean.newTemplate.description}"/>
                    </h:panelGrid>   
                    <p:commandButton  value="Create task" action="#{taskBean.createTask()}"  ajax="false"></p:commandButton>
                   
                </h:form> 
            </div>
            <div class="Post">
                <h:form id="assignmentFile">
                    <p:dataTable id="assignmentFileTable" value="#{taskBean.filesWithTemplate}" var="tasks" rowKey="#{tasks.id}">
                        <p:column headerText="File name">
                            <h:outputText value="#{tasks.fileName}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>
                        <f:facet name="header">
                            <h:outputText value="Files with task" />
                        </f:facet>
                        <p:column headerText="File size">
                            <h:outputText value="#{tasks.fileSize}" />
                        </p:column>
                        <p:column headerText="Action">
                            <p:commandButton value="Download" ajax="false">
                                <p:fileDownload id="koko" value="#{taskBean.download(tasks)}"/>
                            </p:commandButton>
                            <p:commandButton value="Remove" ajax="true"  update=":assignmentFile"  actionListener="#{taskBean.removeFile(tasks)}"/>
                        </p:column>
                        <f:facet name="footer">
                            <h:outputText value=" " />
                        </f:facet>
                    </p:dataTable> 
                </h:form>
            </div>
            <div class="Post">              
                <h:form id="fileUpload" enctype="multipart/form-data" prependId="false">            
                    <h:outputLabel for="Upload" value="Upload file" />
                    <p:fileUpload  id="Upload" sizeLimit="16777216" multiple="true"  fileUploadListener="#{taskBean.handleFileUpload}" allowTypes="/(\.|\/)(pdf|zip|java|jar)$/"  mode="advanced"  update=":assignmentFile:assignmentFileTable" />                  
                </h:form> 
            </div>
            <div class="Post">
                <h:form>

                </h:form>
            </div>
        </ui:define>
    </ui:composition>
</html>